var http = require("http");
var url = require("url");
var qs = require('querystring');

function start(getTyData) {
  function onRequest(request, response) {
    var pathname = url.parse(request.url).pathname;
    //console.log("Request for " + pathname + " received.");
    var queryUrl = url.parse(request.url).query ;
    var sTime =  qs.parse(queryUrl)["startTime"];
    //console.log(qs.parse(queryUrl));
    var eTime =  qs.parse(queryUrl)["endTime"];

    var interface =  qs.parse(queryUrl)["interface"];

    //route(pathname);
    response.writeHead(200, {"Content-Type": "text/json","Access-Control-Allow-Origin":"*"});
    //response.write('{"hello":1}');
    getTyData(response,sTime,eTime,interface);
    //response.end();
    //getTyData(response);
  }

  http.createServer(onRequest).listen(2333);
  console.log("Server has started.");
}

exports.start = start;